<template>
  <div id="AsnDetailList">
    <v-tableTitle :title="$t('security.authSetting')"
                  :btnConfig="btnConfig"
                  :tableSelectData="selectData"
                  @saveUpdate="saveUpdate"></v-tableTitle>
    <v-navMenu :detailNav="detailNav"
               :menuData="menuData"
               @setMentActive="setMentActive"></v-navMenu>
    <div class="detail">
      <component :data="{detailData,argument}"
                 :is="currentComponent"
                 ref="comsRef"></component>
    </div>
  </div>

</template>

<script>
import tableTitle from "commons/TableTitle";
import navMenu from "commons/NavMenu";
import baseMixin from "@/mixins/BaseMixin";
import config from "../Config"

export default {
  name: "DetailList",
  mixins: [baseMixin],
  data () {
    return {
      newFlag: false,
      detailsFlag: false,
      menuData: [
        { label: this.$t('security.window'), index: "1" },
        { label: this.$t('security.wareHouse'), index: "2" },
        { label: this.$t('security.workTable'), index: "3" },
      ],
      argument: {},
      detailData: {},
      selectData: [],
      detailNav: "1",
      componentConfig: [
        {
          name: "permission",
          label: "",
          component: () => import('./page/permission.vue')
        },
        {
          name: "wmwhse",
          label: "",
          component: () => import('./page/wmwhse.vue')
        },
        {
          name: "work",
          label: "",
          component: () => import('./page/work.vue')
        },
      ],
    }
  },
  computed: {
    btnConfig () {
      return [
        {
          label: this.$t('common.save'),certigier: !this.btnPermNameList.includes('EN010204'), invalid: "saveUpdate"
        },
      ]
    },
    currentComponent () {
      return this.componentConfig[this.detailNav - 1].component;
    }
  },
  methods: {
    setMentActive (key) {
      this.detailNav = key;
    },
    // 批量保存
    saveUpdate () {
      let arrs = [];
      if (this.detailNav == '1') {
        this.$refs.comsRef.tableData.forEach(item => {
          let arr1 = {
            ispermission: item.lists ? 1 : 0,
            roleid: item.roleid,
            id: item.id,
            type: 'LIST'
          }
          let arr2 = {
            ispermission: item.edit ? 1 : 0,
            roleid: item.roleid,
            id: item.id,
            type: 'EDIT'
          }
          arrs.push(arr1)
          arrs.push(arr2)
        });
        this.$api.post(`/permission/update`, arrs).then(res => {
          
            this.$message.success(res.returnMgr);
          
        })
      } else if (this.detailNav == '2') {
        this.$refs.comsRef.tableData.forEach(item => {
          let arr1 = {
            active: item.active ? 1 : 0,
            roleid: this.argument.id,
            code: item.code,
          }
          arrs.push(arr1)
        });
        this.$api.post(`/permission/updateWmwhse`, arrs).then(res => {
          
            this.$message.success(res.returnMgr);
          
        })
      } else {
        this.$refs.comsRef.tableData.forEach(item => {
          let arr1 = {
            active: item.active ? 1 : 0,
            roleid: this.argument.id,
            code: item.code,
          }
          arrs.push(arr1)
        });
        this.$api.post(`/permission/updateRtxWord`, arrs).then(res => {
          
            this.$message.success(res.returnMgr);
          
        })
      }

    },
  },
  mounted () {
    if (Object.keys(this.$store.state.skip).length !== 0) {
      let data = this.$store.state.skip;
      this.argument = data.routeData;
      this.detailData = data.detailList;
      this.detailNav = data.detailListNav;
    } else {
      this.argument = this.$store.state.routeData;
    }

  },
  components: {
    "v-tableTitle": tableTitle,
    "v-navMenu": navMenu,
  },
  watch: {}
}
</script>

<style>
</style>
